<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">数字资源统一交易管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>数字资源统一交易管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">项目管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">

		<div class="row mbl">
			<div class="col-lg-12">
				<div class="input-group input-group-sm mbs" style="width:100%;">
					<table style="margin-top: 5px;width:100%;">
						<tr height="50">
							<td align="right" style="width: 80px;">英文名称：&nbsp;&nbsp;</td>
							<td><input type="text" class="form-control" style="width: 100%;" id="nameEn" name="nameEn" /></td>
							<td align="right" style="width: 100px;">中文名称：&nbsp;&nbsp;</td>
							<td><input type="text" class="form-control" style="width: 100%;" id="nameZh" name="nameZh" /></td>
						</tr>
						<tr height="50">
							<td align="right" style="width: 100px;">计费类型：&nbsp;&nbsp;</td>
							<td>
								<select id="type" class="form-control" tyle="width: 100%;">
									<option value="">请选择</option>
									<option value="balance">balance</option>
									<option value="time">time</option>
									<option value="count">count</option>
								</select>
							</td>
							<td align="right" style="width: 100px;">账户类型：&nbsp;&nbsp;</td>
							<td>
								<select id="accountType" class="form-control" tyle="width: 100%;">
									<option value="">请选择</option>
									<option value="Group">机构</option>
									<option value="Person">个人</option>
								</select>
							</td>
							<td align="right" style="width: 100px;">产品：&nbsp;&nbsp;</td>
							<td>
								<select id="repositoryProductId" class="form-control" tyle="width: 100%;">
									<option value="">请选择</option>
									<?for(rp in repositoryProduct){?>
										<option value="${rp.id}">${rp.name}</option>
									<?}?>
								</select>
							</td>
							<td align="right" style="width: 100px;">
								<button type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="demo1(1)">查询</button>
								&nbsp;&nbsp;
							</td>
							<td align="center" style="width: 100px;">
								<button class="btn btn-sm btn-primary" onclick="productAddUpdate('0')">新增</button>
								&nbsp;&nbsp;
							</td>
						</tr>
					</table>
				</div>
			</div>
		</div>

		<table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
						<thead>
							<tr>
								<th>序号</th>
								<th>英文名称</th>
								<th>中文名称</th>
								<th>计费方式</th>
								<th>账户类型</th>
								<th>产品列表</th>
								<th>描述</th>
								<th>可操作</th>
							</tr>
						</thead>
						<tbody id="findMemeber">
						</tbody>
					</table>
					<div id="dataNull" class="panel-body"
						style="height: 90px; line-height: 50px;" align="center"></div>
					<div id="page2" style="text-align: center; margin-top: 20px;"></div>
				</div>
			</div>
		</div>
	</div>
</div>

<!--END CONTENT-->



<?} ?>
<script>
	var curr;
	var id;

	$(function() {

		demo1(1);
	});
	function get() {
		demo1(curr);
	}
	//修改
	function getlay() {
		return id;
	}
	function productAddUpdate(lid) {
		id = lid;
		parent.layer.open({
			type : 2,
			icon : 1,
			title : "项目管理",
			skin : 'layer-ext-moon',
			area : [ '610px', '450px' ],
			fix : false, //不固定
			zIndex : layer.zIndex,
			scrollbar : false,
			shadeClose : true,
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存', '关闭' ],
			content : ["pay_project_management_add_update.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();

			},
			cancel : function(index) {
			}
		});
	}
	//详情页
	function productDetails(lid) {
		id = lid;
		parent.layer.open({
			type : 2,
			icon : 1,
			title : "项目管理",
			skin : 'layer-ext-moon',
			area : [ '800px', '660px' ],
			fix : false, //不固定
			zIndex : layer.zIndex,
			scrollbar : false,
			shadeClose : true,
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : ['关闭'],
			content : ["pay_project_management_details.html", 'no' ],
			
		});
	}

	 function del(id) {
		if (confirm("是否确认删除！！")) {
			$.ajax({
				type : "post",
				url : "./projectdel.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
				if(data[0] == 'yes'){
					demo1();
					layer.msg('删除成功！');
				}else{
					layer.msg('删除失败！与订购管理有关联，请先删除关联...');
				}
					
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	} 
	function demo1(curr) {
		$.getJSON(
			"productfindAll.do",
			{
				page : curr || 1,
				nameEn : $("#nameEn").val(),
				nameZh : $("#nameZh").val(),
				type : $("#type").val(),
				accountType : $("#accountType").val(),
				repositoryProductId : $("#repositoryProductId").val(),
			},
			function(res) {
			//alert(JSON.stringify(res));
				//此处仅仅是为了演示变化的内容
				var text="";
				$("#findMemeber").html("");
				if (res.listsize > 0) {
					$("#dataNull").html("");
				} else {
					$("#dataNull").html(
						"<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
				
				for ( var i = 0; i < res.listsize; i++) {
				//var st = new Array();
					var kk = "";
					//var str = res.result[i].productDetail;
					//str = str.substring(0, str.length - 1);//去掉最后末位的逗号
					//st = str.split(",");
					for (var j = 0; j < res.result[i].productDetail.length; j++) {
						kk += '<label><button type="button" onclick="productDetails('+res.result[i].productDetail[j].id+')" class="label label-green mrs">'
								+ res.result[i].productDetail[j].nameZh + '</button></label>';
					}
					text += "<tr><td>"
							+ (i + 1)
							+ "</td><td> <label >"
							+ res.result[i].nameEn
							+ "</label></td><td><label >"
							+ res.result[i].nameZh
							+ "</label></td><td><label >"
							+ res.result[i].type
							+ "</label></td><td><label >"
							+ res.result[i].accountType
							+ "</label></td>";
					text += "<td>"+kk+"</td>";
					text	+= "<td><label>"
							+ res.result[i].description
							+ "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"productAddUpdate('"
							+ res.result[i].id
							+ "',1)\">"
							+ "编辑"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\" onclick=\"del('"
							+ res.result[i].id
							+ "')\">"
							+ "删除"
							+ "</button></td></tr>";
							
				}
				
				$("#findMemeber").append(text);
	
				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res.pageSize, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr : curr || 1,
					last: res.pageSize,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo1(obj.curr);
							var curr = obj.curr;
							curr = obj.curr;
						}
					}
				});
			});
	};
</script>